
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"  %>

<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>选择分项工程</title>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1">
    <!-- <link rel="shortcut icon" href="/favicon.ico"> -->
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="stylesheet" href="<%=basePath %>/resources/Public/Vendor/SUI/dist/css/sm.min.css">

    <link rel="stylesheet" href="<%=basePath %>/resources/Public/Vendor/SUI/dist/css/sm.min.css">
    <link rel="stylesheet" href="<%=basePath %>/resources/Public/Vendor/SUI/dist/css/sm-extend.min.css">
    <link rel="stylesheet" type="text/css" href="<%=basePath %>/resources/Public/Vendor/icon/iconfont.css">

    <link rel="stylesheet" href="<%=basePath %>/resources/Public/css/common.css">
    <link rel="stylesheet" href="<%=basePath %>/resources/Public/css/common.css">
</head>
<body>
<div class="page-group">

    <div class="page xgj-order-confirm" id='xgj-order-confirm'>

        <div class="content ">
            <div class="list-block">
                <ul>
                    <li>
                        <div class="item-content item-link">
                            <div class="item-inner ">
                                <div class="item-title label">地址：</div>
                                <div class="item-input">
                                    <input type="text" id='city-picker' value="${address.citys}" />
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="item-content">
                            <div class="item-inner adress-detail">
                                <textarea name="" id="address" >${address.address}</textarea>
                                <input type="hidden" id="addressId" value="${address.id}"/>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="item-content ">
                            <div class="item-inner">
                                <div class="item-title label">联系人:</div>
                                <div class="item-input">
                                    <input type="text" id="username" value="${address.uName}" >
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="item-content ">
                            <div class="item-inner">
                                <div class="item-title label">手机号码:</div>
                                <div class="item-input">
                                    <input type="number" id="phone" value="${address.aphone}" >
                                </div>
                            </div>
                        </div>
                    </li>

                </ul>
            </div>
            <div class="list-block" style="margin-top: .5rem;">
                <ul>
                    <li>
                        <div class="item-content ">
                            <div class="item-inner">
                                <div class="item-title label">服务时间：</div>
                                <div class="item-input">
                                    <input type="text" id="serviceTime" value="" >
                                </div>
                            </div>
                        </div>
                    </li>
                </ul>
            </div>
            <div class="card " >
                <div class="card-content card-table">
                    <div class="row">
                        <div class="col-33">服务项目</div>
                        <div class="col-33">数量</div>
                        <div class="col-33">价格</div>
                    </div>
                    <c:forEach items="${business}" var="bus">
                        <div class="row">
                            <div class="col-33">${bus.bName}</div>

                            <div class="col-33">1</div>
                            <div class="col-33">￥${bus.price}</div>
                            <input type="hidden" id="bids" value="${bus.id}">
                            <input type="hidden" id="bName" value="${bus.bName}">
                        </div>
                    </c:forEach>

                    <div class="row" style="padding: .3rem 0;">
                        <span style="color:#F7510B"> 总价：${sumprice}元</span>
                        <input id="money" value="${sumprice}" type="hidden">
                    </div>
                </div>
            </div>
            <div class="card confirm-liuyan" >
                <div class="card-header">留言备注</div>
                <div class="card-content ">
                    <div class="card-content-inner list-block" style="padding: 0 .6rem;">
                        <textarea name="" id="message" placeholder="如有需要，请在此处留言"></textarea>
                    </div>
                </div>
            </div>

            <div class="card" >
                <div class="card-header">上传图片</div>
                <div class="card-content ">
                    <div class="card-content-inner item-confirm-img">
                        <img class=""  src="<%=basePath %>resources/Public/images/demo/avatar.jpg">

                        <span class="icon iconfont icon-tupiantianjia" id='add-pijia-img'></span>
                    </div>
                </div>
            </div>
            <div class="card" style="margin-bottom: 3rem;">
                <div class="card-header">小工匠承诺</div>
                <div class="card-content ">
                    <div class="card-content-inner " style="padding: 0;">
                        <p>1. 下单后，维修师会联系您，确定上门时间</p>
                        <p>2. 维修师傅携带专业设备，上门提供维修、安装服务</p>
                        <p>3. 服务完成后，如您有其他疑问，请咨询客服电话：</p>
                        <p>4. 为了保障您的合法权益和服务质量，避免不必要的损失，请您切勿与维修师傅私下交易（我们无法对私下交易提供安全和质量保障，请您理解）
                        </p>
                    </div>
                </div>
            </div>


        </div>

        <div class=" bar bar-tab row no-gutter">
            <div class="col-60 item-inner-left">
                <a href="javascript:void(0)" class=" ">
                    合计：<span>${sumprice}元</span>
                </a>
            </div>
            <div class="col-40 item-inner-right">
                <input type="hidden" id="openid" value="${openid}">
                <a href="javascript:saveOrder()" class=" ">提交订单</a>
            </div>
        </div>
    </div>
</div>
<!--   此处引入 tabar.html -->
<!-- / 此处引入 tabar.html -->

<script src='<%=basePath %>/resources/Public/Vendor/SUI/dist/js/zepto.js'></script>
<script type="text/javascript">
    $.config = {
        // 路由功能开关过滤器，返回 false 表示当前点击链接不使用路由
        routerFilter: function($link) {
            // 某个区域的 a 链接不想使用路由功能
            if ($link.is('.disable-router a')) {
                return false;
            }
            return true;
        }
    };
</script>
<script src='<%=basePath %>/resources/Public/Vendor/SUI/dist/js/sm.js'></script>
<script src="<%=basePath %>/resources/Public/Vendor/SUI/dist/js/sm-city-picker.min.js" ></script>
<script src='<%=basePath %>/resources/Public/Vendor/SUI/dist/js/sm-extend.min.js'></script>
<script src='<%=basePath %>/resources/Public/js/common.js'></script>



<script type="text/javascript">
    var isSignature=false;
    var trade_no="";
    function saveOrder(){
        if($("#address").val()==""){
            $.toast("请完善详细地址！");
            return;
        }
        if($("#username").val()==""){
            $.toast("联系人不能为空！");
            return;
        }
        if($("#serviceTime").val()==""){
            $.toast("上门时间必须填写！");
            return;
        }
        var address=$("#city-picker").val()+" "+$("#address").val();

        if (isSignature == true) {
            return;
        } else {
            isSignature = true;
        }
        var state = true;
        if(trade_no==""){
            $.ajax({
                url: "<%=path%>/wx/business/saveOrder.do",
                method: 'GET',
                dataType: 'json',
                async: false,
                data: {
                    uname:$("#username").val(),
                    address:address,
                    citys:$("#city-picker").val(),
                    addDetail:$("#address").val(),
                    phone:$("#phone").val(),
                    money:$("#money").val(),
                    bids:$("#bids").val(),
                    message:$("#message").val(),
                    serviceTime:$("#serviceTime").val(),
                    openid:$("#openid").val(),
                    addressId:$("#addressId").val()
                },
                success: function(data){
                    if(data.result=="0000"){
                        trade_no=data.trade_no;
                    }else if(data.result=="1002"){
                        $.toast("超时！");
                        state = false;
                        isSignature = false;
                    }else{
                        $.toast("系统异常！");
                        state = false;
                        isSignature = false;

                    }

                },
                error: function (e) {
                    alert(e);
                    state = false;
                    isSignature = false;
                }
            });
        }

        if (state == false) {
            isSignature = false;
            return;
        }

        var bid = $("#bid").val();
        var bName = $("#bName").val();
        var money = $("#money").val();
        $.ajax({
            type: "POST",
            url: "<%=path%>/wx/business/depositweixin.do",
            data: {
                "bName": bName,
                "bid": bid,
                "money": money,
                "openid": $("#openid").val(),
                "trade_no":trade_no
            },
            dataType: "json",
            success: function (data) {
                if (data.result == "0000") {
                    WeixinJSBridge.invoke(
                        'getBrandWCPayRequest', {
                            "appId": data.appId,     //公众号名称，由商户传入
                            "timeStamp": data.timeStamp,         //时间戳，自1970年以来的秒数
                            "nonceStr": data.nonceStr, //随机串
                            "package": data.packageValue,
                            "signType": "MD5",         //微信签名方式:
                            "paySign": data.paySign    //微信签名
                        },
                        function (res) {
                            if (res.err_msg == "get_brand_wcpay_request:ok") {
                                location.href = "<%=path%>/wx/order/qOrders.do"
                            }
                            isSignature = false;
                        }
                    );

                } else {
                    $.toast("参数配置有误");
                    isSignature = false;
                }
            }
        });
    }

    $("#city-picker").cityPicker({
        toolbarTemplate: '<header class="bar bar-nav">\
    <button class="button button-link pull-right close-picker">确定</button>\
    <h1 class="title">选择服务地址</h1>\
    </header>'
    });
    var date = new Date();
    var year=date.getFullYear();
    var day=date.getDate();
    var month=date.getMonth() + 1;
    var hour=date.getHours();
    var min=date.getMinutes();
    $("#serviceTime").datetimePicker({
        value: [year, month, day, hour, min]
    });
</script>

</body>

</html>